﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XMK.Tadong.Model;
using XMK.Tadong.Biz;
using HU8.Web.FileExplorer.FileExplorer.WebServices;
using System.Configuration;
using HU8.Helpers.Files;
using HU8.Web.FileExplorer;
using System.Data;
using System.IO;

namespace XMK.Tadong.Web.WebFileExplorer.DataSubmit
{
    public partial class NewDataSubmit : FileExplorerPage
    {
        #region 变量

        //获取文档存储路径
        string dataPath = string.Empty;


        #endregion 变量

        #region 事件处理程序

        //提交点击
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitData();
            }
        }

        //提交按钮点击事件
        protected void btnSunmit_Click(object sender, EventArgs e)
        {
            try
            {
                string FolderName = System.DateTime.Now.ToString("yyyyMMdd");
                string spacetype = "";
                string[] spacetypes = new string[3];
                //课题组提交时，当前课题组的ID
                string Team_ID = "";
                if (!string.IsNullOrEmpty(this.Request.QueryString["spacetype"].Trim()))
                {
                    spacetype = this.Request.QueryString["spacetype"];
                    spacetypes = spacetype.Split(',');
                    if (spacetypes.Length >= 3)
                    {
                        Team_ID = spacetypes[1];
                    }
                }
                if (spacetypes[0].Equals("individual"))
                {

                    #region 提交

                    string teams = hidIDS.Value.Trim();
                    teams = teams.TrimEnd(';');
                    string[] team = teams.Split(';');

                    #region 一个用户在一个课题组下

                    if (!string.IsNullOrEmpty(team[0]))
                    {
                        TB_TEAM_FILEInfo model = new TB_TEAM_FILEInfo();
                        TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();

                        #region 在个人空间查找pdf和swf是否有数据

                        TB_PERSON_FILEInfo Pmodel = new TB_PERSON_FILEInfo();
                        TB_PERSON_FILEBiz Pbll = new TB_PERSON_FILEBiz();

                        string P_SWF_PATH = "";
                        string P_PDF_PATH = "";
                        string P_SWF_NAME = "";
                        string P_PDF_NAME = "";
                        string T_SWF_PATH = "";
                        string T_PDF_PATH = "";
                        string T_PATH = "";
                        string P_FILE_SIZE = "";
                        string DiskPath = ConfigurationManager.AppSettings["DiskPath"];
                        string RequestPath = this.Request.QueryString["path"].Replace(DiskPath, "");
                        string RequestName = this.Request.QueryString["filename"];

                        RequestPath = RequestPath.Replace("/" + RequestName, "");
                        string userId = Request.Cookies["user_id"].Value;
                        Pmodel = Pbll.GetFileInfoById(RequestPath);
                        string File_ID = Pmodel.FILE_ID.ToString();
                        Pmodel = Pbll.GetFileInfoById(File_ID);
                        P_FILE_SIZE = Pmodel.FILE_SIZE;

                        T_PATH = "Group/" + FolderName;
                        string g_PATH = DiskPath + T_PATH;
                        if (!Directory.Exists(g_PATH))
                            Directory.CreateDirectory(g_PATH);
                        //原文件
                        string SourFile = DiskPath + Pmodel.SAVE_PATH;
                        string tp = DiskPath + T_PATH;
                        FileHelper.Copy(SourFile, DiskPath + T_PATH);
                        string save_name = Pmodel.SAVE_PATH.Substring(Pmodel.SAVE_PATH.LastIndexOf("/") + 1);
                        
                        //swf文件
                        if (!string.IsNullOrEmpty(Pmodel.SWF_PATH))
                        {
                            P_SWF_PATH = Pmodel.SWF_PATH;
                            P_SWF_NAME = Path.GetFileName(P_SWF_PATH);
                            T_SWF_PATH = "Group/" + FolderName+"/";
                            //复制文件
                            //swf
                            FileHelper.Copy(DiskPath + P_SWF_PATH, DiskPath + T_SWF_PATH);
                        }
                        //pdf文件
                        if (!string.IsNullOrEmpty(Pmodel.PDF_PATH))
                        {
                            P_PDF_PATH = Pmodel.PDF_PATH;
                            P_PDF_NAME = Path.GetFileName(P_PDF_PATH);
                            T_PDF_PATH = "Group/" + FolderName+"/";
                            //pdf
                            FileHelper.Copy(DiskPath + P_PDF_PATH, DiskPath + T_PDF_PATH);
                        }




                        #endregion 在个人空间查找pdf和swf是否有数据

                        model.TEAM_ID = Convert.ToInt32(team[0]);
                        model.FILE_NAME = txtWDMC.Text.Trim();
                        string file_name = model.FILE_NAME.ToString();

                        string FILE_EXT = System.IO.Path.GetExtension(file_name).ToLower();
                        FILE_EXT = FILE_EXT.Replace(".", "");
                        EXTBiz extbiz = new EXTBiz();
                        ExtTypeinfo extmode = extbiz.getExtCodeByExtent(FILE_EXT);
                        FILE_EXT = extmode.EXT_CODE;
                        //FILE_EXT = FILE_EXT.Replace(".", "");
                        //if (FILE_EXT.Equals("doc") || FILE_EXT.Equals("docx"))
                        //{
                        //    model.FILE_EXT = 2;

                        //}
                        //else if (FILE_EXT.Equals("xls") || FILE_EXT.Equals("xlsx"))
                        //{
                        //    model.FILE_EXT = 3;

                        //}
                        //else if (FILE_EXT.Equals("pdf"))
                        //{
                        //    model.FILE_EXT = 4;

                        //}
                        //else if (FILE_EXT.Equals("txt"))
                        //{
                        //    model.FILE_EXT = 5;

                        //}
                        //else if (FILE_EXT.Equals("ppt") || FILE_EXT.Equals("pptx"))
                        //{
                        //    model.FILE_EXT = 6;

                        //}
                        //else
                        //{
                        //    model.FILE_EXT = 1;
                        //}
                        model.FILE_ABST = txtZYXX.Text.Trim();
                        model.FILE_AUTHOR = txtZZ.Text.Trim();
                        model.KEYW = txtGJC.Text.Trim();
                        model.FILE_CRT_TIME = Convert.ToDateTime(paydate.Value.Trim());
                        //model.FILE_VERSION = "";
                        if (!txtMB.Text.Trim().Equals(string.Empty)) model.DEST_OBJ = txtMB.Text.Trim();
                        if (!txtYWDX.Text.Trim().Equals(string.Empty)) model.BIZ_OBJ = txtYWDX.Text.Trim();
                        model.SECRET_LVL = "";
                        model.LANG_TYPE = 0;
                        model.FILE_TYPE = "";
                        model.SAVE_PATH = "Group/" + FolderName + "/" + save_name;
                        model.SWF_PATH = T_SWF_PATH +  P_SWF_NAME;
                        model.PDF_PATH = T_PDF_PATH +  P_PDF_NAME;
                        model.USER_ID = Session["user_id"].ToString();

                        model.STATUS = 0;
                        model.CREATE_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                        model.UPD_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                        model.FILE_SIZE = P_FILE_SIZE;
                        model.DOWN_AMOUNT = 0;
                        if (!bll.Add(model).Equals("0"))
                        {
                            lblError.Text = "提交成功";
                        }
                        else
                        {
                            lblError.Text = "提交失败";
                            //删除文件
                            File.Delete(DiskPath + T_PATH);
                            File.Delete(DiskPath + T_SWF_PATH);
                            File.Delete(DiskPath + T_PDF_PATH);

                        }
                    }
                    #endregion 一个用户在一个课题组下
                    #region 多选课题组，一个用户在多个课题组下
                    else
                    {

                        //多选课题组，一个用户在多个课题组下
                        for (int i = 0; i < cbTeamList.Items.Count; i++)
                        {

                            if (cbTeamList.Items[i].Selected)
                            {

                                TB_TEAM_FILEInfo model = new TB_TEAM_FILEInfo();
                                TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();

                                #region 在个人空间查找pdf和swf是否有数据

                                TB_PERSON_FILEInfo Pmodel = new TB_PERSON_FILEInfo();
                                TB_PERSON_FILEBiz Pbll = new TB_PERSON_FILEBiz();

                                string P_SWF_PATH = "";
                                string P_PDF_PATH = "";
                                string P_SWF_NAME = "";
                                string P_PDF_NAME = "";
                                string T_SWF_PATH = "";
                                string T_PDF_PATH = "";
                                string T_PATH = "";
                                string P_FILE_SIZE = "";
                                string DiskPath = ConfigurationManager.AppSettings["DiskPath"];
                                string RequestPath = this.Request.QueryString["path"].Replace(DiskPath, "");
                                string RequestName = this.Request.QueryString["filename"];

                                RequestPath = RequestPath.Replace("/" + RequestName, "");
                                string userId = Request.Cookies["user_id"].Value;
                                Pmodel = Pbll.GetFileInfoById(RequestPath);
                                string File_ID = Pmodel.FILE_ID.ToString();
                                Pmodel = Pbll.GetFileInfoById(File_ID);
                                P_FILE_SIZE = Pmodel.FILE_SIZE;
                                T_PATH = "Group/" + FolderName;
                                //原文件
                                //FileHelper.Copy(this.Request.QueryString["path"], DiskPath + T_PATH);
                                string SourFile = DiskPath + Pmodel.SAVE_PATH;
                                string tp = DiskPath + T_PATH;
                                FileHelper.Copy(SourFile, DiskPath + T_PATH);
                                string save_name = Pmodel.SAVE_PATH.Substring(Pmodel.SAVE_PATH.LastIndexOf("/") + 1);



                                //swf文件
                                if (!string.IsNullOrEmpty(Pmodel.SWF_PATH))
                                {
                                    P_SWF_PATH = Pmodel.SWF_PATH;
                                    P_SWF_NAME = Path.GetFileName(P_SWF_PATH);
                                    T_SWF_PATH = "Group/" + FolderName+"/";
                                    //复制文件
                                    //swf
                                    FileHelper.Copy(DiskPath + P_SWF_PATH, DiskPath + T_SWF_PATH);
                                }
                                //pdf文件
                                if (!string.IsNullOrEmpty(Pmodel.PDF_PATH))
                                {
                                    P_PDF_PATH = Pmodel.PDF_PATH;
                                    P_PDF_NAME = Path.GetFileName(P_PDF_PATH);
                                    T_PDF_PATH = "Group/" + FolderName+"/";
                                    //pdf
                                    FileHelper.Copy(DiskPath + P_PDF_PATH, DiskPath + T_PDF_PATH);
                                }




                                #endregion 在个人空间查找pdf和swf是否有数据

                                model.TEAM_ID = Convert.ToInt32(cbTeamList.Items[i].Value);
                                model.FILE_NAME = txtWDMC.Text.Trim();
                                string file_name = model.FILE_NAME.ToString();

                                string FILE_EXT = System.IO.Path.GetExtension(file_name).ToLower();
                                FILE_EXT = FILE_EXT.Replace(".", "");
                                EXTBiz extbiz = new EXTBiz();
                                ExtTypeinfo extmode = extbiz.getExtCodeByExtent(FILE_EXT);
                                FILE_EXT = extmode.EXT_CODE;
                                //FILE_EXT = FILE_EXT.Replace(".", "");
                                //if (FILE_EXT.Equals("doc") || FILE_EXT.Equals("docx"))
                                //{
                                //    model.FILE_EXT = 2;

                                //}
                                //else if (FILE_EXT.Equals("xls") || FILE_EXT.Equals("xlsx"))
                                //{
                                //    model.FILE_EXT = 3;

                                //}
                                //else if (FILE_EXT.Equals("pdf"))
                                //{
                                //    model.FILE_EXT = 4;

                                //}
                                //else if (FILE_EXT.Equals("txt"))
                                //{
                                //    model.FILE_EXT = 5;

                                //}
                                //else if (FILE_EXT.Equals("ppt") || FILE_EXT.Equals("pptx"))
                                //{
                                //    model.FILE_EXT = 6;

                                //}
                                //else
                                //{
                                //    model.FILE_EXT = 1;
                                //}
                                model.FILE_ABST = txtZYXX.Text.Trim();
                                model.FILE_AUTHOR = txtZZ.Text.Trim();
                                model.KEYW = txtGJC.Text.Trim();
                                model.FILE_CRT_TIME = Convert.ToDateTime(paydate.Value.Trim());
                                //model.FILE_VERSION = "";
                                if (!txtMB.Text.Trim().Equals(string.Empty)) model.DEST_OBJ = txtMB.Text.Trim();
                                if (!txtYWDX.Text.Trim().Equals(string.Empty)) model.BIZ_OBJ = txtYWDX.Text.Trim();
                                model.SECRET_LVL = "";
                                model.LANG_TYPE = 0;
                                model.FILE_TYPE = "";
                                model.SAVE_PATH = "Group/" + FolderName + "/" + save_name;
                                model.SWF_PATH = T_SWF_PATH +  P_SWF_NAME;
                                model.PDF_PATH = T_PDF_PATH + P_PDF_NAME;
                                model.USER_ID = Session["user_id"].ToString();
                                model.STATUS = 0;
                                model.CREATE_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                                model.UPD_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                                model.FILE_SIZE = P_FILE_SIZE;
                                model.DOWN_AMOUNT = 0;
                                if (!bll.Add(model).Equals("0"))
                                {
                                    lblError.Text = "提交成功";
                                }
                                else
                                {
                                    lblError.Text = "提交失败";
                                    //删除文件
                                    File.Delete(DiskPath + T_PATH);
                                    File.Delete(DiskPath + T_SWF_PATH);
                                    File.Delete(DiskPath + T_PDF_PATH);

                                }
                            }
                        }

                    }
                    #endregion 多选课题组，一个用户在多个课题组下

                    #endregion
                }
                else if (spacetypes[0].Equals("group"))
                {
                    #region 在课题组空间查找提交的pdf和swf是否有数据

                    TB_TEAM_FILEInfo Tmodel = new TB_TEAM_FILEInfo();
                    TB_TEAM_FILEBiz Tbll = new TB_TEAM_FILEBiz();

                    string T_SWF_PATH = "";
                    string T_PDF_PATH = "";
                    string T_SWF_NAME = "";
                    string T_PDF_NAME = "";



                    string X_SWF_PATH = "";
                    string X_PDF_PATH = "";
                    string X_PATH = "";
                    string T_FILE_SIZE = "";
                    string DiskPath = ConfigurationManager.AppSettings["DiskPath"];
                    string RequestPath = this.Request.QueryString["path"].Replace(DiskPath, "");
                    string RequestName = this.Request.QueryString["filename"];

                    RequestPath = RequestPath.Replace("/" + RequestName, "");
                    //默认课题组id，避免代码错误，曹哥需修改
                    string teamid = spacetypes[1].ToString();
                    DataTable dt = Tbll.GetModel(RequestPath);
                    string File_ID = dt.Rows[0]["File_ID"].ToString();
                    DataTable dt1 = Tbll.GetModel(File_ID);
                    T_FILE_SIZE = dt1.Rows[0]["FILE_SIZE"].ToString();
                    X_PATH = "Project/" + FolderName;
                    string P_PATH = DiskPath + X_PATH;
                    if (!Directory.Exists(P_PATH))
                        Directory.CreateDirectory(P_PATH);
                    //原文件
                    string SourFile = DiskPath + dt1.Rows[0]["SAVE_PATH"].ToString();
                    
                    FileHelper.Copy(SourFile, DiskPath + X_PATH);
                    string save_name = dt1.Rows[0]["SAVE_PATH"].ToString().Substring(dt1.Rows[0]["SAVE_PATH"].ToString().LastIndexOf("/") + 1);
                    
                   
                    //swf文件
                    if (!string.IsNullOrEmpty(dt1.Rows[0]["SWF_PATH"].ToString()))
                    {
                        T_SWF_PATH = dt1.Rows[0]["SWF_PATH"].ToString();
                        T_SWF_NAME = Path.GetFileName(T_SWF_PATH);
                        X_SWF_PATH = "Project/" + FolderName + "/";
                        //复制文件
                        //swf
                        FileHelper.Copy(DiskPath + T_SWF_PATH, DiskPath + X_SWF_PATH);
                    }
                    //pdf文件
                    if (!string.IsNullOrEmpty(dt1.Rows[0]["PDF_PATH"].ToString()))
                    {
                        T_PDF_PATH = dt1.Rows[0]["PDF_PATH"].ToString();
                        T_PDF_NAME = Path.GetFileName(T_PDF_PATH);
                        X_PDF_PATH = "Project/" + FolderName + "/";
                        //复制文件
                        //swf
                        FileHelper.Copy(DiskPath + T_PDF_PATH, DiskPath + X_PDF_PATH);
                    }




                    #endregion 在课题组空间查找提交的
                    #region 课题组提交
                    TB_XMK_FILEInfo model = new TB_XMK_FILEInfo();
                    Tb_Xmk_FileBiz bll = new Tb_Xmk_FileBiz();

                    model.TEAM_ID = Convert.ToInt32(hidIDS.Value);
                    model.FILE_NAME = txtWDMC.Text.Trim();
                    string file_name = model.FILE_NAME.ToString();
                    string FILE_EXT = System.IO.Path.GetExtension(file_name).ToLower();
                    FILE_EXT = FILE_EXT.Replace(".", "");
                    EXTBiz extbiz = new EXTBiz();
                    ExtTypeinfo extmode = extbiz.getExtCodeByExtent(FILE_EXT);
                    FILE_EXT = extmode.EXT_CODE;
                    //FILE_EXT = FILE_EXT.Replace(".", "");
                    //if (FILE_EXT.Equals("doc") || FILE_EXT.Equals("docx"))
                    //{
                    //    model.FILE_EXT = 2;

                    //}
                    //else if (FILE_EXT.Equals("xls") || FILE_EXT.Equals("xlsx"))
                    //{
                    //    model.FILE_EXT = 3;

                    //}
                    //else if (FILE_EXT.Equals("pdf"))
                    //{
                    //    model.FILE_EXT = 4;

                    //}
                    //else if (FILE_EXT.Equals("txt"))
                    //{
                    //    model.FILE_EXT = 5;

                    //}
                    //else if (FILE_EXT.Equals("ppt") || FILE_EXT.Equals("pptx"))
                    //{
                    //    model.FILE_EXT = 6;

                    //}
                    model.FILE_ABST = txtZYXX.Text.Trim();
                    model.FILE_AUTHOR = txtZZ.Text.Trim();
                    model.KEYW = txtGJC.Text.Trim();
                    model.FILE_CRT_DATE = Convert.ToDateTime(paydate.Value.Trim());
                    model.FILE_VERSION = 1;
                    if (!txtMB.Text.Trim().Equals(string.Empty)) model.DEST_OBJ = txtMB.Text.Trim();
                    if (!txtYWDX.Text.Trim().Equals(string.Empty)) model.BIZ_OBJ = txtYWDX.Text.Trim();
                    model.SECRET_LVL = "";
                    model.LANG_TYPE = 0;
                    model.FILE_TYPE = "";
                    model.SAVE_PATH = "Project/" + FolderName + "/" + save_name;
                    model.PDF_PATH = X_SWF_PATH + T_PDF_NAME;
                    model.SWF_PATH = X_PDF_PATH + T_SWF_NAME;
                    model.USER_ID = Session["user_id"].ToString();
                    model.STATUS = 0;
                    model.CREATE_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    model.UPD_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                    model.FILE_SIZE = T_FILE_SIZE;
                    model.DOWN_AMOUNT = 0;
                    if (bll.Add(model))
                    {
                        lblError.Text = "提交成功";
                    }
                    else
                    {
                        lblError.Text = "提交失败";
                        //删除文件
                        File.Delete(DiskPath + X_PATH);
                        File.Delete(DiskPath + X_SWF_PATH);
                        File.Delete(DiskPath + X_PDF_PATH);

                    }
                    #endregion 课题组提交
                }
                else
                {
                    #region 重新提交


                    if (!string.IsNullOrEmpty(this.Request.QueryString["File_ID"]))
                    {
                        TB_TEAM_FILEInfo model = new TB_TEAM_FILEInfo();
                        TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();
                        model.FILE_ID = Convert.ToInt32(this.Request.QueryString["File_ID"]);
                        model.TEAM_ID = Convert.ToInt32(hidIDS.Value);
                        model.FILE_NAME = txtWDMC.Text.Trim();
                        string file_name = model.FILE_NAME.ToString();
                        string FILE_EXT = file_name.Substring(file_name.IndexOf(".") + 1, file_name.Length);
                        EXTBiz extbiz = new EXTBiz();
                        ExtTypeinfo extmode = extbiz.getExtCodeByExtent(FILE_EXT);
                        FILE_EXT = extmode.EXT_CODE;
                        //if (FILE_EXT.Equals("doc") || FILE_EXT.Equals("docx") || FILE_EXT.Equals("DOC") || FILE_EXT.Equals("DOCX"))
                        //{
                        //    model.FILE_EXT = 2;

                        //}
                        //else if (FILE_EXT.Equals("xls") || FILE_EXT.Equals("xlsx") || FILE_EXT.Equals("XLS") || FILE_EXT.Equals("XLSX"))
                        //{
                        //    model.FILE_EXT = 3;

                        //}
                        //else if (FILE_EXT.Equals("pdf") || FILE_EXT.Equals("PDF"))
                        //{
                        //    model.FILE_EXT = 4;

                        //}
                        //else if (FILE_EXT.Equals("txt") || FILE_EXT.Equals("TXT"))
                        //{
                        //    model.FILE_EXT = 5;

                        //}
                        //else if (FILE_EXT.Equals("ppt") || FILE_EXT.Equals("pptx") || FILE_EXT.Equals("PPT") || FILE_EXT.Equals("PPTX"))
                        //{
                        //    model.FILE_EXT = 6;

                        //}
                        model.FILE_ABST = txtZYXX.Text.Trim();
                        model.FILE_AUTHOR = txtZZ.Text.Trim();
                        model.KEYW = txtGJC.Text.Trim();
                        model.FILE_CRT_TIME = Convert.ToDateTime(paydate.Value.Trim());
                        //model.FILE_VERSION = "";
                        if (!txtMB.Text.Trim().Equals(string.Empty)) model.DEST_OBJ = txtMB.Text.Trim();
                        if (!txtYWDX.Text.Trim().Equals(string.Empty)) model.BIZ_OBJ = txtYWDX.Text.Trim();
                        model.SECRET_LVL = "";
                        model.LANG_TYPE = 0;
                        model.FILE_TYPE = "";
                        //model.SAVE_PATH = "Group/" + +FolderName;
                        //model.SWF_PATH = "Group/" + model.TEAM_ID + "/待审核/SWF";
                        //model.PDF_PATH = "Group/" + model.TEAM_ID + "/待审核/PDF";
                        model.USER_ID = Session["user_id"].ToString();
                        model.STATUS = 0;
                        model.CREATE_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                        model.UPD_TIME = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
                        if (bll.Update(model))
                        {
                            lblError.Text = "提交成功";
                        }
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }

        #endregion 事件处理程序

        #region 函数集

        //页面加载函数 
        public void InitData()
        {
            try
            {

                TB_TEAM_FILEInfo model = new TB_TEAM_FILEInfo();
                TB_TEAM_FILEBiz bll = new TB_TEAM_FILEBiz();
                string File_ID = string.Empty;
                string FileName = "";
                string SavePath = "";
                if (!string.IsNullOrEmpty(this.Request.QueryString["path"]))
                {
                    hidPath.Value = this.Request.QueryString["path"].ToString();
                    SavePath = this.Request.QueryString["path"].ToString();
                }
                //获取文档名称
                if (!string.IsNullOrEmpty(this.Request.QueryString["filename"]))
                {
                    txtWDMC.Text = this.Request.QueryString["filename"].ToString();
                    FileName = this.Request.QueryString["filename"].ToString();
                }
                if (!string.IsNullOrEmpty(this.Request.QueryString["File_ID"]))
                {
                    File_ID = this.Request.QueryString["File_ID"].ToString();
                }

                string spacetype = "";
                string[] spacetypes = new string[3];
                string Team_ID = "";
                if (!string.IsNullOrEmpty(this.Request.QueryString["spacetype"].Trim()))
                {
                    spacetype = this.Request.QueryString["spacetype"];
                    spacetypes = spacetype.Split(',');
                    if (spacetypes.Length >= 3)
                    {
                        Team_ID = spacetypes[1];
                    }
                }
                if (spacetypes[0].Equals("individual"))
                {
                    div.Visible = true;

                    BindTeamList();


                }
                else if (spacetypes[0].Equals("group"))
                {

                    string DiskPath = ConfigurationManager.AppSettings["DiskPath"];
                    //SavePath = SavePath.Replace(DiskPath, "");
                    ////string RequestName = this.Request.QueryString["filename"];

                    //SavePath = SavePath.Replace("/" + FileName, "");

                    div.Visible = false;
                    //课题组ID
                    string teamid = spacetypes[1];
                    DataTable dt = bll.GetModel(SavePath);
                    if (dt.Rows.Count > 0)
                    {
                        hidIDS.Value = dt.Rows[0]["TEAM_ID"].ToString();
                        txtWDMC.Text = dt.Rows[0]["FILE_NAME"].ToString();
                        txtZYXX.Text = dt.Rows[0]["FILE_ABST"].ToString();
                        txtZZ.Text = dt.Rows[0]["FILE_AUTHOR"].ToString();
                        txtGJC.Text = dt.Rows[0]["KEYW"].ToString();
                        paydate.Value = Convert.ToDateTime(dt.Rows[0]["FILE_CRT_TIME"].ToString()).ToString("yyyy-MM-dd");
                        txtMB.Text = dt.Rows[0]["DEST_OBJ"].ToString();
                        targetValue.Value = dt.Rows[0]["DEST_OBJ"].ToString();
                        txtYWDX.Text = dt.Rows[0]["BIZ_OBJ"].ToString();
                        bizValue.Value = dt.Rows[0]["BIZ_OBJ"].ToString();

                    }
                }

                if (!string.IsNullOrEmpty(File_ID))
                {

                    DataTable dt = bll.GetModel(File_ID);
                    if (dt.Rows.Count > 0)
                    {
                        hidIDS.Value = dt.Rows[0]["TEAM_ID"].ToString();
                        txtWDMC.Text = dt.Rows[0]["FILE_NAME"].ToString();
                        txtZYXX.Text = dt.Rows[0]["FILE_ABST"].ToString();
                        txtZZ.Text = dt.Rows[0]["FILE_AUTHOR"].ToString();
                        txtGJC.Text = dt.Rows[0]["KEYW"].ToString();
                        paydate.Value = dt.Rows[0]["FILE_CRT_TIME"].ToString();
                        txtMB.Text = dt.Rows[0]["DEST_OBJ"].ToString();
                        targetValue.Value = dt.Rows[0]["DEST_OBJ"].ToString();
                        txtYWDX.Text = dt.Rows[0]["BIZ_OBJ"].ToString();
                        bizValue.Value = dt.Rows[0]["BIZ_OBJ"].ToString();

                    }

                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
        }

        /// <summary>
        /// 绑定课题组
        /// </summary>
        public void BindTeamList()
        {
           // string User_ID = Request.Cookies["_userId_"].Value;
            
            //Tb_TeamBiz teambll = new Tb_TeamBiz();
            //DataTable dt = teambll.GetUTeamList(User_ID);
            string User_ID = Session["user_id"].ToString();
            Tb_Team_UserBiz team_userBiz = new Tb_Team_UserBiz();
            //DataTable dt = team_userBiz.GetTeamListByUserId(userId);
            List<Base_UserSpaceInfo> spaces = team_userBiz.GetSpaceListByUserId(User_ID);
            if (spaces.Count == 1 && spaces[0].SpaceName != "项目库空间")
            {
                cbTeamList.Visible = false;
                lblteam.Visible = true;
                hidIDS.Value =spaces[0].SpaceId.ToString()+ ";";
                lblteam.Text = spaces[0].SpaceName.ToString();
            }
            else
            {
                DataTable teamdt = new DataTable();
                teamdt.Columns.Add("TEAM_ID", typeof(System.String));
                teamdt.Columns.Add("TEAM_NAME", typeof(System.String));
                for (int i = 0; i < spaces.Count; i++)
                {
                    //decimal teamid = (decimal)dt.Rows[i]["TEAM_ID"];
                    //Tb_TeamBiz tb_teamBiz = new Tb_TeamBiz();
                    //TB_TEAMInfo team = tb_teamBiz.GetTeamInfoById(teamid);
                    if (spaces[i].IsOpen && spaces[i].SpaceName != "项目库空间")
                    {
                        DataRow row = teamdt.NewRow();
                        row["TEAM_ID"] = spaces[i].SpaceId;
                        row["TEAM_NAME"] = spaces[i].SpaceName;
                        teamdt.Rows.Add(row);
                    }

                }
                cbTeamList.Visible = true;
                lblteam.Visible = false;
                cbTeamList.DataSource = teamdt;
                cbTeamList.DataBind();
            }

        }

        /// <summary>
        /// 文件复制
        /// </summary>
        /// <param name="source">源文件地址</param>
        /// <param name="destination">目标地址</param>
        /// <returns>成功返回true，失败返回false</returns>
        public bool FileCopy(string source, string destination)
        {
            bool ret = false;
            System.IO.FileInfo file_s = new System.IO.FileInfo(source);
            System.IO.FileInfo file_d = new System.IO.FileInfo(destination);
            if (file_s.Exists)
            {
                if (!file_d.Exists)
                {
                    file_s.CopyTo(destination);
                    ret = true;
                }
            }
            if (ret == true)
            {
                Response.Write("<script>alert('复制文件成功！');</script>");
            }
            else
            {
                Response.Write("<script>alert('复制文件失败！');</script>");
            }
            return ret;
        }

        #endregion 函数集
    }
}